package com.itheima.ydd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.itheima.ydd.common.R;
import com.itheima.ydd.entry.SysConfig;
import com.itheima.ydd.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *后台系统配置表 sys_config
 */
@RestController
@RequestMapping("/index")
public class SysConfigController {
    @Autowired
    private SysConfigService sysConfigService;
    @GetMapping("/getConfig")
    public R getConfig(){
        //查询系统管理配置
        LambdaQueryWrapper<SysConfig> lqw =new LambdaQueryWrapper<>();
        lqw.eq(SysConfig::getTab_value,"system");
        List<SysConfig> list = sysConfigService.list(lqw);

        //得到总数居组装返回前端需要的数据
        Map<String,String> resMap =new HashMap<>();
        list.forEach(sysConfig -> {
            resMap.put(sysConfig.getAttr_key(),sysConfig.getAttr_value());
        });
        return R.success(resMap);
    }



}
